package com.kvn.idpt;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created by wangzhiyuan on 2019/1/11
 */
public class IdptRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotationAttributes annoAttrs = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableIdptTransactional.class.getName()));
        boolean ddlAuto = annoAttrs.getBoolean("ddlAuto");
        BeanDefinitionBuilder beanDef = BeanDefinitionBuilder.genericBeanDefinition((IdptTransactionAspect.class));
        beanDef.addPropertyValue("ddlAuto", ddlAuto);
        registry.registerBeanDefinition(IdptTransactionAspect.class.getSimpleName(), beanDef.getBeanDefinition());
    }

}
